﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//new
using DataRecv.enums;

namespace DataRecv
{
    public partial class Form_diyname : Form
    {

        public string diy_pass;
        public bool iskk;



        public Form_diyname()
        {
            InitializeComponent();
        }

        private void Form_diyname_Load(object sender, EventArgs e)
        {
            try
            {
                this.textBox_splitor.Text = (iskk ? G.SystemParam.KKNameSplitor : G.SystemParam.DJNameSplitor);

               string diy_show = diy_pass;
                if (diy_pass.Contains(this.textBox_splitor.Text + "指定字符"))
                {
                    diy_show = diy_pass.Replace(this.textBox_splitor.Text + "指定字符", "");
                }
                if (diy_show.Contains("指定字符"))
                {
                    diy_show = diy_show.Replace("指定字符", "");
                }
                

                this.label_diy.Text = diy_show;
                string[] dd = null;
                if ((diy_pass != null) && (diy_pass != "") && (this.textBox_splitor.Text!=""))
                {
                    dd = diy_pass.Split(new string[] { this.textBox_splitor.Text }, StringSplitOptions.RemoveEmptyEntries);
                }
                this.flowLayoutPanel1.Controls.Clear();

                string[] ss = Enum.GetNames(typeof(Enum_DiyName));
                if (ss != null)
                {
                    foreach (string s in ss)
                    {
                        if (s.Contains("指定字符") == false)
                        {
                            CheckBox box = new CheckBox();
                            box.Text = s;
                            if (dd != null)
                            {
                                foreach (string d in dd)
                                {
                                    if (d == s)
                                    {
                                        box.Checked = true;
                                        break;
                                    }
                                }
                            }
                            box.CheckedChanged += new EventHandler(box_CheckedChanged);
                            this.flowLayoutPanel1.Controls.Add(box);
                        }
                    }
                }
            }
            catch { }
        }


        void box_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                CheckBox box = sender as CheckBox;
                if (box.Checked == true)
                {
                    if (this.label_diy.Text == "")
                    {
                        this.label_diy.Text += box.Text;
                    }
                    else
                    {
                        this.label_diy.Text += (this.textBox_splitor.Text + box.Text);
                    }

                    if (diy_pass == "")
                    {
                        diy_pass += box.Text;
                    }
                    else
                    {
                        diy_pass += (this.textBox_splitor.Text + box.Text);
                    }
                }
            }
            catch { }
        }

        private void button_reset_Click(object sender, EventArgs e)
        {
            try
            {
                this.label_diy.Text = "";
                diy_pass = "";
                if ((this.flowLayoutPanel1.Controls != null) && (this.flowLayoutPanel1.Controls.Count > 0))
                {
                    foreach (Control c in this.flowLayoutPanel1.Controls)
                    {
                        ((CheckBox)c).Checked = false;
                    }
                }
            }
            catch { }
        }

        private void button_save_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox_spchar.Text.Contains("_"))
                {
                    MessageBox.Show("指定字符包含_时，会影响实时上传");
                }


                if (this.iskk == true)
                {
                    if (this.textBox_splitor.Text != "")
                    {
                        bool b = G.SystemParam.Save(Enum_SystemParamName.KKNameSplitor, this.textBox_splitor.Text);
                        if (b == true)
                        {
                            G.SystemParam.KKNameSplitor = this.textBox_splitor.Text;
                        }
                    }
                }
                else
                {
                    if (this.textBox_splitor.Text != "")
                    {
                        bool bb = G.SystemParam.Save(Enum_SystemParamName.DJNameSplitor, this.textBox_splitor.Text);
                        if (bb == true)
                        {
                            G.SystemParam.DJNameSplitor = this.textBox_splitor.Text;
                        }
                    }
                }

                
                this.Close();

            }
            catch { }
        }

        private void button_spchar_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox_spchar.Text != "")
                {
                    // /\:"<>|*
                    if (textBox_spchar.Text.Contains("\\"))
                    {
                        MessageBox.Show("指定字符不能包含\\"); return;
                    }
                    if (textBox_spchar.Text.Contains("/"))
                    {
                        MessageBox.Show("指定字符不能包含/"); return;
                    }
                    if (textBox_spchar.Text.Contains(":"))
                    {
                        MessageBox.Show("指定字符不能包含:"); return;
                    }
                    if (textBox_spchar.Text.Contains("\""))
                    {
                        MessageBox.Show("指定字符不能包含\""); return;
                    }
                    if (textBox_spchar.Text.Contains("<"))
                    {
                        MessageBox.Show("指定字符不能包含<"); return;
                    }
                    if (textBox_spchar.Text.Contains(">"))
                    {
                        MessageBox.Show("指定字符不能包含>"); return;
                    }
                    if (textBox_spchar.Text.Contains("|"))
                    {
                        MessageBox.Show("指定字符不能包含|"); return;
                    }
                    if (textBox_spchar.Text.Contains("*"))
                    {
                        MessageBox.Show("指定字符不能包含*"); return;
                    }

                    if (textBox_spchar.Text.Contains("_"))
                    {
                        MessageBox.Show("指定字符包含_时，会影响实时上传");
                    }

                    
                    this.label_diy.Text += (textBox_spchar.Text);
                    

                    if (diy_pass == "")
                    {
                        diy_pass += ("指定字符" + textBox_spchar.Text);
                    }
                    else
                    {
                        diy_pass += (this.textBox_splitor.Text + "指定字符" + textBox_spchar.Text);
                    }
                }
                else
                {
                    MessageBox.Show("指定字符不能为空");

                }
            }
            catch { }
        }
    }
}
